package DesignPatern.A19_访问者模式.QSB.A03_高级模式;

/**
 * @Author: Du
 * @Date: 2021/8/6 8:52
 * <p>
 * 访问者模式是通过一个类将其他需要访问的信息都放入到这个类中
 * 在基础类中封装一个accept方法
 */
public class Visitor implements IVisitor
{
    @Override
    public void visit(CommonEmployee commonEmployee)
    {
        System.out.println(this.getCommonEmployee(commonEmployee));
    }
    
    @Override
    public void visit(Manager manager)
    {
        System.out.println(this.getManagerInfo(manager));
    }
    
    private String getBasicInfo(Employee employee)
    {
        String Info = "姓名" + employee.getName() + "性别" + employee.getSex() + "薪水" + employee.getSalary() + "\n";
        return Info;
    }
    
    private String getManagerInfo(Manager manager)
    {
        String basicInfo = this.getBasicInfo(manager) + "\n";
        String otherInfo = "业绩：" + manager.getPerformance() + "\n";
        return basicInfo + otherInfo;
    }
    
    private String getCommonEmployee(CommonEmployee commonEmployee)
    {
        String basicInfo = this.getBasicInfo(commonEmployee) + "\n";
        String otherInfo = "工作：" + commonEmployee.getJob() + "\n";
        return basicInfo + otherInfo;
    }
}
